import turtle
import math

def draw_circle(pen, x, y, filled, radius):
    pen.pensize(1)
    pen.penup()
    pen.goto(x, y - radius)
    pen.pendown()
    pen.color('black')  # 设置边框颜色为黑色

    if filled:
        pen.fillcolor('black')  # 设置填充颜色为黑色
    else:
        pen.fillcolor('white')  # 设置填充颜色为白色

    pen.begin_fill()  # 开始填充
    pen.circle(radius)
    pen.end_fill()  # 结束填充
    
def draw_square(pen, pen_color, pen_size, x, y, length):
    pen.color(pen_color)
    pen.pensize(pen_size)
    pen.penup()
    pen.goto(x - length / 2, y - length / 2)
    pen.setheading(0)
    pen.pendown()
    for _ in range(4):
        pen.forward(length)
        pen.left(90)

def draw_line(pen, x, y, angle, length):
    pen.penup()
    pen.goto(x, y)
    pen.pendown()
    pen.setheading(angle)
    pen.forward(length)

def draw_board(pen, step_len, j):
    center_x = j * (4 * step_len)
    center_y = 0

    # 绘制开始的三个方块
    for i in range(3):
        length_i = step_len * (i + 1)
        draw_square(pen, 'black', 1, center_x, center_y, length_i)

    # 绘制8条线段
    draw_line(pen, center_x - step_len / 2, center_y, 180, step_len)
    draw_line(pen, center_x + step_len / 2, center_y, 0, step_len)
    draw_line(pen, center_x, center_y - step_len / 2, 270, step_len)
    draw_line(pen, center_x, center_y + step_len / 2, 90, step_len)
    draw_line(pen, center_x - step_len / 2, center_y + step_len / 2, 135, step_len * math.sqrt(2))
    draw_line(pen, center_x + step_len / 2, center_y + step_len / 2, 45, step_len * math.sqrt(2))
    draw_line(pen, center_x + step_len / 2, center_y - step_len / 2, -45, step_len * math.sqrt(2))
    draw_line(pen, center_x - step_len / 2, center_y - step_len / 2, -135, step_len * math.sqrt(2))

    # 绘制红色的方块
    draw_square(pen, 'red', 3, center_x, center_y, 2 * step_len)

    draw_circle(pen, center_x - step_len, center_y, j + 0.5, step_len/5 )
